

using System;
using System.Collections.Generic;
using System.Text;
using EntityLayer;
using System.Data;
using DataAccessLayer;
using InfraStructureLayer;

namespace DataLayer
{
	public class datNews
	{
		public datNews()
		{
		}
		
		#region  Code Factory Generated Methods
		public void DeleteNewsByNewsId(entNews parEntNews, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pNewsId",parEntNews.NewsId);
			parDbConnector.ExecuteNonQuery("DeleteNewsByNewsId",insDbParamCollection);
		}
		public void InsertNews(entNews parEntNews, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pNewsDescription",parEntNews.NewsDescription);
			insDbParamCollection.Add("@pInsertDate",parEntNews.InsertDate);
			insDbParamCollection.AddOutput("@pNewsId",DbType.Int32);
			parDbConnector.ExecuteNonQuery("InsertNews",insDbParamCollection);
			parEntNews.NewsId = Convert.ToInt32(insDbParamCollection.GetOutPutParameter().Value);
		}
		public void UpdateNewsByNewsId(entNews parEntNews, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pNewsId",parEntNews.NewsId);
			
			insDbParamCollection.Add("@pNewsDescription",parEntNews.NewsDescription);
			insDbParamCollection.Add("@pInsertDate",parEntNews.InsertDate);
			parDbConnector.ExecuteNonQuery("UpdateNewsByNewsId",insDbParamCollection);
		}
		public DataTable SelectNews(DbConnector parDbConnector)
		{
			
			return parDbConnector.ExecuteDataTable("SelectNews",null);
		}
		public void SelectNewsByNewsId(entNews parEntNews, DbConnector parDbConnector)
		{
			DbParamCollection insDbParamCollection = new DbParamCollection();
			insDbParamCollection.Add("@pNewsId",parEntNews.NewsId);
			DataTable insDataTable = new DataTable();
			insDataTable = parDbConnector.ExecuteDataTable("SelectNewsByNewsId",insDbParamCollection);
			if (insDataTable.Rows.Count>0)
			{
				if (insDataTable.Rows[0]["NewsId"]!=DBNull.Value)
				{
					parEntNews.NewsId = Convert.ToInt32(insDataTable.Rows[0]["NewsId"]);
				}
				if (insDataTable.Rows[0]["NewsDescription"]!=DBNull.Value)
				{
					parEntNews.NewsDescription = insDataTable.Rows[0]["NewsDescription"].ToString();
				}
				if (insDataTable.Rows[0]["InsertDate"]!=DBNull.Value)
				{
					parEntNews.InsertDate = Convert.ToDateTime(insDataTable.Rows[0]["InsertDate"]);
				}
			}
		}
		
		#endregion

        public DataTable SelectNewsLatest(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectNewsLatest", insDbParamCollection);
        }
        public DataTable SelectNewsByLanguageId(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectNewsByLanguageId", insDbParamCollection);
        }
        public DataTable SelectNewsArchive(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectNewsArchive", insDbParamCollection);
        }
        public DataTable SelectNewsByLanguageIdAndYearAndMonth(entNews parEntNews, DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pYear", parEntNews.InsertDate.Year);
            insDbParamCollection.Add("@pMonth", parEntNews.InsertDate.Month);
            return parDbConnector.ExecuteDataTable("SelectNewsByLanguageIdAndYearAndMonth", insDbParamCollection);
        }
        public DataTable SelectNewsLatestMainPage(DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            return parDbConnector.ExecuteDataTable("SelectNewsLatestMainPage", insDbParamCollection);
        }
        public DataTable SelectNewsByDateMainPage(entNews parEntNews,DbConnector parDbConnector)
        {
            DbParamCollection insDbParamCollection = new DbParamCollection();
            insDbParamCollection.Add("@pLanguageId", CurrentContext.LanguageId);
            insDbParamCollection.Add("@pInsertDate", parEntNews.InsertDate);
            return parDbConnector.ExecuteDataTable("SelectNewsByDateMainPage", insDbParamCollection);
        }
	}
}